<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title>申请教练</title>
        <meta name="viewport" content="width=device-width,initial-scale=1">
        <link rel="stylesheet" href="information.css">
        <link rel="stylesheet" href="normalize.css">
        <link rel="stylesheet" href="../public_css/public_header.css">
    </head>
    <body>
        <header class=" public_header">
            <div class="public_header_return">
                <img src="../public_img/return.png" alt="" class="public_header_return" onclick="history.back(-1)">
                <p>教练注册申请</p>
            </div>
        </header>
        <section class="mainbody">
            <br/>
            <br/>
            <br/>
            <br/>
            <form class="information_collect clearfix" >
                <span>姓名:</span>
                <input class="message_input" type="text" id="name">
                <br/>
                <span>身份证号:</span>
                <input class="message_input" type="text" id="idcard">
                <br/>
                <span>教练证号:</span>
                <input class="message_input" type="text" id="teachcard">
                <br/>
                <div class="checkbox_default">
                    <input type="checkbox" id="drive_argument" name="drive_argument">我已阅读《i驾车教练注册协议》
                    <label id="label_btn2" for="drive_argument"></label>
                </div>
                <br/>
                <input class="submit_final"  id="regBtn" type="button"   value="提交">
            </form>
        </section>
        <script src="jquery.min.js"></script>
        <script src="picturefill.js"></script>
        <script src="information.js"></script>
        <script src="../layer.js"></script>
        <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=HZE4scXysMPZY1HMDTkI4cYSjRo13zZG"></script>
        <script type="text/javascript">
            $(".information_btn1").click(function(){
                history.back();
            });
            $(function () {
                var geolocation = new BMap.Geolocation();
                geolocation.getCurrentPosition(function(r) {
                    var gps_w = r.point.lat;
                    var gps_j = r.point.lng;
                    console.log(gps_w);
                    console.log(gps_j);
                    $(".submit_final").click(function(){
                        var name = $("#name").val();
                        if(name==""){
                            layer.msg("姓名不能为空");
                            return false;
                        }
                        if(gps_j=='' && gps_w==''){
                            gps_j=0;
                            gps_w=0;
                        }
                        var idcard = $("#idcard").val();
                        if(idcard==""){
                            layer.msg("身份证不能为空");
                            return false;
                        }else if (!/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$|^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X)$/i.test(idcard)){
                            layer.msg("请填写合法的身份证号");
                            return false;
                        }
                        var teachcard = $("#teachcard").val();
                        if(teachcard==""){
                            layer.msg("教练证号不能为空");
                            return false;
                        }
                        var token =localStorage.phone;
                        if(!$('#drive_argument').prop('checked')){
                            layer.msg("请先阅读i驾车教练注册协议");
                            return false;
                        }
                        $.ajax({
                            url:"https://newapp.icandrive.cn/api/applyTeacher.php",
                            data:{token:token,name:name,ID_number:idcard,teacher_number:teachcard,gps_j:gps_j,gps_w:gps_w},
                            dataType:'json',
                            type:'post',
                            success:function(data){
                                if(data.status==402){
                                    layer.msg("认证系统服务关闭");
                                }
                                if(data.status==403){
                                    layer.msg("身份信息不匹配");
                                }
                                if(data.status==200){
                                    layer.msg("申请成功，请等待审核");
                                    setInterval(function(){
                                        window.location.href="../my/me.html";
                                    },2000);
                                }
                                if(data.status==500){
                                    layer.msg("请重新登陆");

                                    setInterval(function(){
                                        window.location.href="../login/log_in.html";
                                    },2000)
                                }
                                if(data.status==450){
                                    layer.msg("您已申请过，请等待审核");
                                }
                                if(data.status==400){
                                    layer.msg(data.msg);
                                }
                            },
                            error:function(){
                                layer.msg('系统维护中',function(){
                                    history.go(0)
                                },1000);
                            }
                        });
                    });
                });

            });


        </script>

        <script>
            document.addEventListener("plusready", function() {
                // 注册返回按键事件
                plus.key.addEventListener('backbutton', function() {
                    window.history.back();
                }, false);
                //此处false代表不退出页面，如果为true回退到上一个一面
            });
        </script>
    </body>
</html>
